<template>
  <div class="salary-analysis">
    <el-row :gutter="20">
      <!-- 工资概览卡片 -->
      <el-col :span="6" v-for="card in salaryCards" :key="card.title">
        <el-card class="statistics-card">
          <div class="card-content">
            <div class="card-value" :class="card.type">{{ card.value }}</div>
            <div class="card-title">{{ card.title }}</div>
            <div class="card-trend" :class="card.trend > 0 ? 'up' : 'down'">
              {{ card.trend > 0 ? '+' : '' }}{{ card.trend }}%
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="charts-row">
      <!-- 工资趋势图 -->
      <el-col :span="12">
        <el-card class="chart-card">
          <template #header>
            <div class="card-header">
              <span>工资趋势</span>
              <el-radio-group v-model="timeRange" size="small">
                <el-radio-button label="month">月度</el-radio-button>
                <el-radio-button label="quarter">季度</el-radio-button>
                <el-radio-button label="year">年度</el-radio-button>
              </el-radio-group>
            </div>
          </template>
          <div class="chart-container">
            <!-- 这里将添加工资趋势图表 -->
          </div>
        </el-card>
      </el-col>

      <!-- 部门工资分布图 -->
      <el-col :span="12">
        <el-card class="chart-card">
          <template #header>
            <div class="card-header">
              <span>部门工资分布</span>
            </div>
          </template>
          <div class="chart-container">
            <!-- 这里将添加部门工资分布图表 -->
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 工资明细表格 -->
    <el-card class="salary-list">
      <template #header>
        <div class="list-header">
          <span>工资明细</span>
          <div class="header-right">
            <el-select v-model="selectedMonth" placeholder="选择月份" size="small">
              <el-option
                v-for="month in months"
                :key="month.value"
                :label="month.label"
                :value="month.value"
              />
            </el-select>
            <el-input
              v-model="searchQuery"
              placeholder="搜索"
              class="search-input"
              size="small"
            >
              <template #prefix>
                <el-icon><Search /></el-icon>
              </template>
            </el-input>
          </div>
        </div>
      </template>

      <el-table :data="filteredSalary" style="width: 100%">
        <el-table-column prop="name" label="姓名" width="100" />
        <el-table-column prop="department" label="部门" width="120" />
        <el-table-column prop="position" label="职位" width="120" />
        <el-table-column prop="baseSalary" label="基本工资" width="120">
          <template #default="scope">
            ￥{{ scope.row.baseSalary.toLocaleString() }}
          </template>
        </el-table-column>
        <el-table-column prop="bonus" label="奖金" width="120">
          <template #default="scope">
            ￥{{ scope.row.bonus.toLocaleString() }}
          </template>
        </el-table-column>
        <el-table-column prop="deduction" label="扣除" width="120">
          <template #default="scope">
            ￥{{ scope.row.deduction.toLocaleString() }}
          </template>
        </el-table-column>
        <el-table-column prop="total" label="实发工资">
          <template #default="scope">
            <span class="total-salary">
              ￥{{ scope.row.total.toLocaleString() }}
            </span>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          layout="total, sizes, prev, pager, next"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { Search } from '@element-plus/icons-vue'

const timeRange = ref('month')
const selectedMonth = ref('')
const searchQuery = ref('')
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(100)

const salaryCards = ref([
  {
    title: '平均工资',
    value: '￥8,562',
    type: 'primary',
    trend: 5.2
  },
  {
    title: '最高工资',
    value: '￥15,000',
    type: 'success',
    trend: 3.8
  },
  {
    title: '最低工资',
    value: '￥4,500',
    type: 'warning',
    trend: 2.1
  },
  {
    title: '工资总额',
    value: '￥856,200',
    type: 'info',
    trend: 4.5
  }
])

const months = [
  { label: '2024年3月', value: '2024-03' },
  { label: '2024年2月', value: '2024-02' },
  { label: '2024年1月', value: '2024-01' }
]

// 模拟工资数据
const salaryData = ref([
  {
    name: '张三',
    department: '研发部',
    position: '工程师',
    baseSalary: 8000,
    bonus: 2000,
    deduction: 500,
    total: 9500
  },
  // 更多数据...
])

const filteredSalary = computed(() => {
  return salaryData.value.filter(item =>
    Object.values(item).some(val =>
      val.toString().toLowerCase().includes(searchQuery.value.toLowerCase())
    )
  )
})

const handleSizeChange = (val) => {
  pageSize.value = val
}

const handleCurrentChange = (val) => {
  currentPage.value = val
}
</script>

<style scoped>
.salary-analysis {
  padding: 20px;
}

.statistics-card {
  margin-bottom: 20px;
}

.card-content {
  text-align: center;
}

.card-value {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 8px;
}

.card-value.primary {
  color: #409EFF;
}

.card-value.success {
  color: #67C23A;
}

.card-value.warning {
  color: #E6A23C;
}

.card-value.info {
  color: #909399;
}

.card-title {
  font-size: 14px;
  color: #909399;
  margin-bottom: 8px;
}

.card-trend {
  font-size: 12px;
}

.card-trend.up {
  color: #67C23A;
}

.card-trend.down {
  color: #F56C6C;
}

.charts-row {
  margin-bottom: 20px;
}

.chart-card {
  height: 400px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-container {
  height: 320px;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-right {
  display: flex;
  gap: 16px;
}

.search-input {
  width: 200px;
}

.total-salary {
  font-weight: bold;
  color: #409EFF;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style> 